<?php
namespace app\index\controller;
use app\common\model;

class Index extends Base {
    public $phoneModel;
    public $routerModel;
    public $wechatModel;
    public function __construct() {
        parent::__construct();
        $this->routerModel = new model\Router();
        $this->phoneModel = new model\Phone();
        $this->wechatModel = new model\Wechat();
    }

    public function wifi () {

        /* $arr = [
            'appId' => 'wx1db3121a7832c6c4',
            'extend' => 'test',
            'timestamp' => (int)(microtime(true)*1000),
            'sign' => '',
            'shopId' => '17180599',
            'authUrl' => 'http://wifi.gogogo.club/index/notify/MQNCJ9Wn',
            'mac' => 'b4:0b:44:b6:4e:cf',//b4:0b:44:b6:4e:cf//b4:06:44:ac:d5:61
            'ssid' => 'Tenda_BF0140'
        ];
        $string = $arr['appId'].$arr['extend'].$arr['timestamp'].$arr['shopId'].$arr['authUrl'].$arr['mac'].$arr['ssid'].'636308fbdedce6571f724d4f72646b03';
        */
       /*  $arr = [
            'appId' => 'wx1db3121a7832c6c4',
            'extend' => 'test',
            'timestamp' => (int)(microtime(true)*1000),
            'sign' => '',
            'shopId' => '17187462',
            'authUrl' => 'http://wifi.gogogo.club/index/notify/MQNCJ9Wn',
            'mac' => 'b4:0b:44:b6:4e:cf',//b4:0b:44:b6:4e:cf//b4:06:44:ac:d5:61
            'ssid' => 'ChinaNet-HB'
        ];
        $string = $arr['appId'].$arr['extend'].$arr['timestamp'].$arr['shopId'].$arr['authUrl'].$arr['mac'].$arr['ssid'].'bf1d57aeacb5691f60c3e2fa570df557';
       
        $arr['sign'] = md5($string);
        $this->assign('wifi',$arr);
        return view();
 */
        $input = input();
        $router = $this->routerModel->getOne(['id'=>$input['router_id']]);
        $wechat = $this->wechatModel->getOne(['appid'=>$router['appid']]);
        $phone = $this->phoneModel->getOne(['id'=>$input['phone_id']]);
        $arr = [
            'appId' => $wechat['appid'],
            'extend' => 'test',
            'timestamp' => (int)(microtime(true)*1000),
            'sign' => '',
            'shopId' => $wechat['shop_id'],
            'authUrl' => 'http://wifi.gogogo.club/index/notify/MQNCJ9Wn',
            'mac' => $phone['phone_mac'],
            'ssid' => $router['ssid']
        ];
        $string = $arr['appId'].$arr['extend'].$arr['timestamp'].$arr['shopId'].$arr['authUrl'].$arr['mac'].$arr['ssid'].$router['secretkey'];
        $arr['sign'] = md5($string);
        $url = "https://wifi.weixin.qq.com/operator/callWechat.xhtml?appId={$arr['appId']}&extend={$arr['extend']}&timestamp={$arr['timestamp']}".
                "&sign={$arr['sign']}&shopId={$arr['shopId']}&mac={$arr['mac']}&ssid={$arr['ssid']}&authUrl=".urlencode($arr['authUrl']);
        $re=file_get_contents($url);
       /*  $this->assign('wifi',$arr);
        return view(); */
    }
    /* 
    $arr = [
            'appId' => 'wxd13f152a00d5a71f',
            'extend' => 'test',
            'timestamp' => (int)(microtime(true)*1000),
            'sign' => '',
            'shopId' => '17166643',
            'authUrl' => 'http://wifi.gogogo.club/index/notify/MQNCJ9Wn',
            'mac' => 'b4:0b:44:ac:d5:61',//b4:0b:44:b6:4e:cf//b4:06:44:ac:d5:61
            'ssid' => 'waoo888'
        ];
        $string = $arr['appId'].$arr['extend'].$arr['timestamp'].$arr['shopId'].$arr['authUrl'].$arr['mac'].$arr['ssid'].'2724364a6f58dc3cfaabeb0b91aa87e7';
        $arr['sign'] = md5($string);
        $this->assign('wifi',$arr);
        return view();
         */

}
